var form;

$(document).ready(function () {
    layui.use('form', function () {
        var form = layui.form;
        form.render();
        getCategory();
    });
});

function getCategory() {

    var id = $('#id').val();

    ajax(
        "/admin/category/getCategory", "POST",
        { categoryId: id }
        ,true, true, false
    ).done(function (returnData) {

        $("input[name='categoryId']").val(returnData.categoryId);
        $("input[name='categoryName']").val(returnData.categoryName);
        $("input[name='categoryUnit']").val(returnData.categoryUnit);
        $("input[name='categoryPrice']").val(returnData.categoryPrice);
        $("input[name='categoryDesc']").val(returnData.categoryDesc);

        form.render();

    });

}

function editCategory() {

    var formJSON = $("#category-submit-form").serializeObject();

    // 编辑收费类别
    ajax(
        "/admin/category/editCategory", "POST",
        formJSON, true, true, true
    ).done(function () {
        loadingPage("/admin/category/category");
    });

}